package com.ruoyi.mp.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.db.domain.system.PcGoldConfig;
import com.ruoyi.db.domain.system.PcProduct;
import com.ruoyi.db.mapper.system.PcGoldConfigMapper;
import com.ruoyi.db.mapper.system.PcProductMapper;
import com.ruoyi.mp.service.IPcProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.List;

/**
 * 【商城产品】Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-23
 */
@Service
@Transactional(rollbackOn = Exception.class)
public class PcProductServiceImpl implements IPcProductService
{
    @Autowired
    private PcProductMapper pcProductMapper;
    @Autowired
    private PcGoldConfigMapper pcGoldConfigMapper;

    /**
     * 查询【商城产品】
     * 
     * @param proId 【商城产品】主键
     * @return 【商城产品】
     */
    @Override
    public PcProduct selectPcProductByProId(Long proId)
    {
        PcProduct pro = pcProductMapper.selectPcProductByProId(proId);
        BigDecimal rmbPrice = pro.getRmbPrice()==null?new BigDecimal(0):pro.getRmbPrice();
        if(pro.getReturnRate()!=null){
            pro.setReturnGold((pro.getReturnRate()).setScale( 2, BigDecimal.ROUND_HALF_UP ));
        }else{
            pro.setReturnGold(new BigDecimal(0));
        }
        return pro;
    }

    /**
     * 查询【商城产品】列表
     * 
     * @param pcProduct 【商城产品】
     * @return 【商城产品】
     */
    @Override
    public List<PcProduct> selectPcProductList(PcProduct pcProduct)
    {
        List<PcProduct> pros =  pcProductMapper.selectPcProductListOrderSort(pcProduct);
        for (PcProduct pro: pros) {
            BigDecimal rmbPrice = pro.getRmbPrice()==null?new BigDecimal(0):pro.getRmbPrice();
            if(pro.getReturnRate()!=null){
                pro.setReturnGold((pro.getReturnRate()).setScale( 2, BigDecimal.ROUND_HALF_UP ));
            }else{
                pro.setReturnGold(new BigDecimal(0));
            }
        };
        return pros;
    }

}
